<?php
namespace backend\components;
use backend\models\AgNavbar;
use backend\models\AgNavitem;
use mdm\admin\components\MenuHelper;
use yii\base\Widget;
use yii\helpers\Html;

/**
 * 根据传入的id返回二三级菜单数据
 */
class NavbarWidget extends Widget
{
    public $uid;
    public function run()
    {
        $callback = function ($menu) {
            $data = eval($menu['data']);
            return [
                'id' => $menu['id'],
                'name' => $menu['name'],
                'icon' => $menu['icon'],
                'url' => $menu['route'],
                'pid' => $menu['parent'],
                'options' => $data,
                'children' => $menu['children']
            ];
        };
        $menuList = MenuHelper::getAssignedMenu($this->uid,100000,$callback,true);
        return $this->render('@app/views/layouts/sidebar', [
            "sidebar"=>$menuList,
         ]);
    }


}
